﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Entity.ModelConfiguration;
using DomusDotNet.Sbm.ObjectModel;
using System.Data.Entity.ModelConfiguration.Configuration; 

namespace DomusDotNet.Sbm.ObjectModel.Configurations
{
    public class BookConfiguration : EntityTypeConfiguration<Book>
    {
        public BookConfiguration (){
            Property(b => b.Title).IsConcurrencyToken();
            Property(b => b.Title).HasMaxLength(120);
            Property(b => b.ISBN).HasMaxLength(80);
        }
    }

    public class MemberConfiguration : EntityTypeConfiguration<Member>
    {
        public MemberConfiguration()
        {
            Property(m => m.Name).HasMaxLength(30);
            Property(m => m.Username).HasMaxLength(30);
            Property(m => m.Password).HasMaxLength(15).IsUnicode(false);
            Property(m => m.Phone).HasMaxLength(15);
            Property(m => m.Surname ).HasMaxLength(30);
        }
    }

    public class AddressConfiguration : ComplexTypeConfiguration<Address>
    {
        public AddressConfiguration()
        {
            Property(a => a.ZipCode).HasMaxLength(5).IsUnicode(false).IsFixedLength();
        }
    }

    //public class LimitStringLengthConvention : IConfigurationConvention<PropertyInfo, StringPropertyConfiguration>
    //{
    //    public void Apply(PropertyInfo memberInfo, Func<StringPropertyConfiguration> configuration)
    //    {
    //        configuration().MaxLength = 200;
    //    }
    //}
}
